import {computed, ref} from 'vue'
import {keyBind} from '@/utils/keymasterTool.ts'
import {HotDreamVideo} from '@/data/Dream'

export function usePagination(list: HotDreamVideo[]) {
    const pageSize = 12
    const page = ref(1)
    const pageList = computed(() => {
        return list.slice((page.value - 1) * pageSize, page.value * pageSize)
    })
    const pageCount = computed(() => {
        return Math.ceil(list.length / pageSize)
    })
    // 快捷键翻页
    keyBind('left', null, () => {
        if (page.value == 1) {
            page.value = pageCount.value
        } else {
            page.value--
        }
    })
    keyBind('right', null, () => {
        if (page.value == pageCount.value) {
            page.value = 1
        } else {
            page.value++
        }
    })
    return {
        page,
        pageSize,
        pageList,
    }
}